package com.daoeping.dao;

import java.util.List;
import org.json.JSONArray;
import com.daoeping.dao.AllDaoSupport;
import com.daoeping.data.Bzn_questionfavgroup;
import com.daoeping.data.Bzn_questionfavorite;
import com.daoeping.domain.JsonData;
import com.daoeping.util.ConverntJsonData;

public class Bzn_questionfavgroupDAO extends AllDaoSupport {
	public JsonData findBzn_questionfavgroupList(Bzn_questionfavorite bzn_questionfavorite){
		String hql = "select favgroup.name , favgroup.id from Bzn_questionfavorite fav left join fav.bzn_questionfavgroup favgroup where fav.usr_user.id='"+bzn_questionfavorite.getUsr_user().getId()+"' and fav.bzn_question.id is null ";
		if(bzn_questionfavorite.getBzn_questionfavgroup()!=null){
			hql = hql + " and fav.bzn_questionfavgroup.id != '"+bzn_questionfavorite.getBzn_questionfavgroup().getId()+"'";
		}
		hql = hql + "order by fav.id";
		List<Object[]> resultlist = (List<Object[]>)this.selectDataByHQL(hql);
		JSONArray jsonArray = new ConverntJsonData().getJsonData(resultlist);
		JsonData jsonData = new JsonData();
		jsonData.setJsonData(jsonArray+"");
		return jsonData;
	}
	
	public Bzn_questionfavgroup findBzn_questionfavgroupById(Bzn_questionfavgroup bzn_questionfavgroup){
		List<Bzn_questionfavgroup> bzn_questionfavgroupList =  (List<Bzn_questionfavgroup>)this.selectDataByHQL("from Bzn_questionfavgroup bzn where bzn.id = '"+bzn_questionfavgroup.getId()+"'");
		if(bzn_questionfavgroupList.size()==1){
			return bzn_questionfavgroupList.get(0);
		}else{
			return null;
		}
	}
}